home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_11 / 9n11030a < prev    next >
Text File  |  1991-08-26  |  2KB  |  57 lines

  1.  
  2. /* --------------------------------------------------------------
  3.  
  4. FUNCTION LOCATE_NODE: The steps to locating a node in the list are:
  5.  
  6. A.  Make one cycle of the list starting at the root. Since process idle
  7.     has priority zero and the user cannot add nodes with a priority less
  8.     than 1, the idle node is always the last one in the cycle.
  9.  
  10. B.  If the priority we are searching for is equal to the current 
  11.     entry's, return the previous entry's address.
  12.  
  13. C.  Else if the new priority is greater than that in the list the one we 
  14.     are searching for isn't in the list.  So is we were looking for
  15.     an exact match indicate it wasn't found.  For an inexact match
  16.     return the address of the previous node (which must be greater than
  17.     the one we are searching for).
  18.  
  19. D.  The match may still be coming so keep looking.
  20.  
  21. E.  We've reached the end of the list so is we were looking for
  22.     an exact match indicate it wasn't found.  For an inexact match
  23.     return the address of the previous node (which must be greater than
  24.     the one we are searching for).
  25.  
  26. -------------------------------------------------------------- */
  27.  
  28. Node *locate_node(unsigned priority, int match)
  29. {
  30.     const Node *pnode = proot_node;
  31.  
  32. /*A*/    while (pnode->process != idle) {
  33. /*B*/        if (priority == pnode->priority) {
  34.             return pnode->pbwd;
  35.         }
  36. /*C*/        else if (priority > pnode->priority) {
  37.             if (match == EXACT) {
  38.                 return NULL;
  39.             }
  40.             else {
  41.                 return pnode->pbwd;
  42.             }
  43.         }
  44. /*D*/        else {
  45.             pnode = pnode->pfwd;
  46.         }
  47.     }
  48.  
  49. /*E*/    if (match == EXACT) {
  50.         return NULL;
  51.     }
  52.     else {
  53.         return pnode->pbwd;
  54.     }
  55. }
  56.  
  57.